package ch05.d1;

import ch04.d3.Animal;
import org.junit.Test;

import java.util.Arrays;

public class ArrayTest {
    @Test
    public void testNew(){
        // 长度 元素 下标
        // 最大的下标=长度-1
        int[] a=new int[5]; //[数组长度] 5个元素构造
        //[下标] 0 1 2 3 4

        for (int i = 0; i < 5; i++) {
            System.out.println(a[i]);
        }
    }
    @Test
    public void testNew2(){
        int[] a={23,4,2,7,3,9};
        //统计大于5的元素个数
        //统计所有数字之和
        //查找有没有数字7
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }

    @Test
    public void testNew3() {
        //数组长度不可变
        int[] a = {23, 4, 2, 7, 3, 9};
        a[5]=10;
        System.out.println(a);//6个元素
        int[] b=Arrays.copyOf(a,10);
        System.out.println(b);//10个元素

        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

    }

    @Test
    public void testNew4(){
//        int[] a=new int[Integer.MAX_VALUE];
//        System.out.println(a.length);
        String[] b=new String[10];

        System.out.println(b);
        System.out.println(Arrays.toString(b));

        Animal[] c=new Animal[10];
        System.out.println(c);
        System.out.println(Arrays.toString(c));
    }





}
